home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / wgdb-42.lha / wgdb-4.2 / gdb / breakpoint.c < prev    next >
C/C++ Source or Header  |  1992-09-11  |  63KB  |  2,448 lines

  1. /* Everything about breakpoints, for GDB.
  2.    Copyright (C) 1986, 1987, 1989, 1990 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include <stdio.h>
  21. #include <ctype.h>
  22. #include "defs.h"
  23. #include "param.h"
  24. #include "symtab.h"
  25. #include "frame.h"
  26. #include "breakpoint.h"
  27. #include "expression.h"
  28. #include "gdbcore.h"
  29. #include "gdbcmd.h"
  30. #include "value.h"
  31. #include "ctype.h"
  32. #include "command.h"
  33. #include "inferior.h"
  34. #include "target.h"
  35. #include "language.h"
  36. #include <string.h>
  37.  
  38. extern int addressprint;        /* Print machine addresses? */
  39. extern int demangle;            /* Print de-mangled symbol names? */
  40.  
  41. extern int catch_errors ();
  42. extern void set_next_address ();    /* ...for x/ command */
  43.  
  44. /* Are we executing breakpoint commands?  */
  45. static int executing_breakpoint_commands;
  46.  
  47. /* States of enablement of breakpoint.
  48.    `temporary' means disable when hit.
  49.    `delete' means delete when hit.  */
  50.  
  51. enum enable { disabled, enabled, temporary, delete};
  52.  
  53. /* Not that the ->silent field is not currently used by any commands
  54.    (though the code is in there if it was to be, and set_raw_breakpoint
  55.    does set it to 0).  I implemented it because I thought it would be
  56.    useful for a hack I had to put in; I'm going to leave it in because
  57.    I can see how there might be times when it would indeed be useful */
  58.  
  59. /* This is for a breakpoint or a watchpoint.  */
  60.  
  61. struct breakpoint
  62. {
  63.   struct breakpoint *next;
  64.   /* Number assigned to distinguish breakpoints.  */
  65.   int number;
  66.   /* Address to break at, or NULL if not a breakpoint.  */
  67.   CORE_ADDR address;
  68.   /* Line number of this address.  Redundant.  Only matters if address
  69.      is non-NULL.  */
  70.   int line_number;
  71.   /* Symtab of file of this address.  Redundant.  Only matters if address
  72.      is non-NULL.  */
  73.   struct symtab *symtab;
  74.   /* Zero means disabled; remember the info but don't break here.  */
  75.   enum enable enable;
  76.   /* Non-zero means a silent breakpoint (don't print frame info
  77.      if we stop here). */
  78.   unsigned char silent;
  79.   /* Number of stops at this breakpoint that should
  80.      be continued automatically before really stopping.  */
  81.   int ignore_count;
  82.   /* "Real" contents of byte where breakpoint has been inserted.
  83.      Valid only when breakpoints are in the program.  Under the complete
  84.      control of the target insert_breakpoint and remove_breakpoint routines.
  85.      No other code should assume anything about the value(s) here.  */
  86.   char shadow_contents[BREAKPOINT_MAX];
  87.   /* Nonzero if this breakpoint is now inserted.  Only matters if address
  88.      is non-NULL.  */
  89.   char inserted;
  90.   /* Nonzero if this is not the first breakpoint in the list
  91.      for the given address.  Only matters if address is non-NULL.  */
  92.   char duplicate;
  93.   /* Chain of command lines to execute when this breakpoint is hit.  */
  94.   struct command_line *commands;
  95.   /* Stack depth (address of frame).  If nonzero, break only if fp
  96.      equals this.  */
  97.   FRAME_ADDR frame;
  98.   /* Conditional.  Break only if this expression's value is nonzero.  */
  99.   struct expression *cond;
  100.  
  101.   /* String we used to set the breakpoint (malloc'd).  Only matters if
  102.      address is non-NULL.  */
  103.   char *addr_string;
  104.   /* String form of the breakpoint condition (malloc'd), or NULL if there
  105.      is no condition.  */
  106.   char *cond_string;
  107.  
  108.   /* The expression we are watching, or NULL if not a watchpoint.  */
  109.   struct expression *exp;
  110.   /* The largest block within which it is valid, or NULL if it is
  111.      valid anywhere (e.g. consists just of global symbols).  */
  112.   struct block *exp_valid_block;
  113.   /* Value of the watchpoint the last time we checked it.  */
  114.   value val;
  115. };
  116.  
  117. #define ALL_BREAKPOINTS(b)  for (b = breakpoint_chain; b; b = b->next)
  118.  
  119. /* Chain of all breakpoints defined.  */
  120.  
  121. struct breakpoint *breakpoint_chain;
  122.  
  123. /* Number of last breakpoint made.  */
  124.  
  125. static int breakpoint_count;
  126.  
  127. /* Set breakpoint count to NUM.  */
  128. static void
  129. set_breakpoint_count (num)
  130.      int num;
  131. {
  132.   breakpoint_count = num;
  133.   set_internalvar (lookup_internalvar ("bpnum"),
  134.            value_from_longest (builtin_type_int, (LONGEST) num));
  135. }
  136.  
  137. /* Default address, symtab and line to put a breakpoint at
  138.    for "break" command with no arg.
  139.    if default_breakpoint_valid is zero, the other three are
  140.    not valid, and "break" with no arg is an error.
  141.  
  142.    This set by print_stack_frame, which calls set_default_breakpoint.  */
  143.  
  144. int default_breakpoint_valid;
  145. CORE_ADDR default_breakpoint_address;
  146. struct symtab *default_breakpoint_symtab;
  147. int default_breakpoint_line;
  148.  
  149. static void delete_breakpoint ();
  150. void breakpoint_auto_delete ();
  151.  
  152. /* Flag indicating extra verbosity for xgdb.  */
  153. extern int xgdb_verbose;
  154.  
  155. /* *PP is a string denoting a breakpoint.  Get the number of the breakpoint.
  156.    Advance *PP after the string and any trailing whitespace.
  157.  
  158.    Currently the string can either be a number or "$" followed by the name
  159.    of a convenience variable.  Making it an expression wouldn't work well
  160.    for map_breakpoint_numbers (e.g. "4 + 5 + 6").  */
  161. static int
  162. get_number (pp)
  163.      char **pp;
  164. {
  165.   int retval;
  166.   char *p = *pp;
  167.  
  168.   if (p == NULL)
  169.     /* Empty line means refer to the last breakpoint.  */
  170.     return breakpoint_count;
  171.   else if (*p == '$')
  172.     {
  173.       /* Make a copy of the name, so we can null-terminate it
  174.      to pass to lookup_internalvar().  */
  175.       char *varname;
  176.       char *start = ++p;
  177.       value val;
  178.  
  179.       while (isalnum (*p) || *p == '_')
  180.     p++;
  181.       varname = (char *) alloca (p - start + 1);
  182.       strncpy (varname, start, p - start);
  183.       varname[p - start] = '\0';
  184.       val = value_of_internalvar (lookup_internalvar (varname));
  185.       if (TYPE_CODE (VALUE_TYPE (val)) != TYPE_CODE_INT)
  186.     error (
  187. "Convenience variables used to specify breakpoints must have integer values."
  188.            );
  189.       retval = (int) value_as_long (val);
  190.     }
  191.   else
  192.     {
  193.       while (*p >= '0' && *p <= '9')
  194.     ++p;
  195.       if (p == *pp)
  196.     /* There is no number here.  (e.g. "cond a == b").  */
  197.     error_no_arg ("breakpoint number");
  198.       retval = atoi (*pp);
  199.     }
  200.   if (!(isspace (*p) || *p == '\0'))
  201.     error ("breakpoint number expected");
  202.   while (isspace (*p))
  203.     p++;
  204.   *pp = p;
  205.   return retval;
  206. }
  207.  
  208. /* condition N EXP -- set break condition of breakpoint N to EXP.  */
  209.  
  210. static void
  211. condition_command (arg, from_tty)
  212.      char *arg;
  213.      int from_tty;
  214. {
  215.   register struct breakpoint *b;
  216.   char *p;
  217.   register int bnum;
  218.  
  219.   if (arg == 0)
  220.     error_no_arg ("breakpoint number");
  221.  
  222.   p = arg;
  223.   bnum = get_number (&p);
  224.  
  225.   ALL_BREAKPOINTS (b)
  226.     if (b->number == bnum)
  227.       {
  228.     if (b->cond)
  229.       {
  230.         free (b->cond);
  231.         b->cond = 0;
  232.       }
  233.     if (b->cond_string != NULL)
  234.       free (b->cond_string);
  235.  
  236.     if (*p == 0)
  237.       {
  238.         b->cond = 0;
  239.         b->cond_string = NULL;
  240.         if (from_tty)
  241.           printf ("Breakpoint %d now unconditional.\n", bnum);
  242.       }
  243.     else
  244.       {
  245.         arg = p;
  246.         /* I don't know if it matters whether this is the string the user
  247.            typed in or the decompiled expression.  */
  248.         b->cond_string = savestring (arg, strlen (arg));
  249.         b->cond = parse_exp_1 (&arg, block_for_pc (b->address), 0);
  250.         if (*arg)
  251.           error ("Junk at end of expression");
  252.       }
  253.     return;
  254.       }
  255.  
  256.   error ("No breakpoint number %d.", bnum);
  257. }
  258.  
  259. /* ARGSUSED */
  260. static void
  261. commands_command (arg, from_tty)
  262.      char *arg;
  263.      int from_tty;
  264. {
  265.   register struct breakpoint *b;
  266.   char *p;
  267.   register int bnum;
  268.   struct command_line *l;
  269.  
  270.   /* If we allowed this, we would have problems with when to
  271.      free the storage, if we change the commands currently
  272.      being read from.  */
  273.  
  274.   if (executing_breakpoint_commands)
  275.     error ("Can't use the \"commands\" command among a breakpoint's commands.");
  276.  
  277.   p = arg;
  278.   bnum = get_number (&p);
  279.   if (p && *p)
  280.     error ("Unexpected extra arguments following breakpoint number.");
  281.       
  282.   ALL_BREAKPOINTS (b)
  283.     if (b->number == bnum)
  284.       {
  285.     if (from_tty && input_from_terminal_p ())
  286.       {
  287.         printf ("Type commands for when breakpoint %d is hit, one per line.\n\
  288. End with a line saying just \"end\".\n", bnum);
  289.         fflush (stdout);
  290.       }
  291.     l = read_command_lines ();
  292.     free_command_lines (&b->commands);
  293.     b->commands = l;
  294.     return;
  295.       }
  296.   error ("No breakpoint number %d.", bnum);
  297. }
  298.  
  299. extern int memory_breakpoint_size; /* from mem-break.c */
  300.  
  301. /* Like target_read_memory() but if breakpoints are inserted, return
  302.    the shadow contents instead of the breakpoints themselves.  */
  303. int
  304. read_memory_nobpt (memaddr, myaddr, len)
  305.      CORE_ADDR memaddr;
  306.      char *myaddr;
  307.      unsigned len;
  308. {
  309.   int status;
  310.   struct breakpoint *b;
  311.  
  312.   if (memory_breakpoint_size < 0)
  313.     /* No breakpoints on this machine.  */
  314.     return target_read_memory (memaddr, myaddr, len);
  315.   
  316.   ALL_BREAKPOINTS (b)
  317.     {
  318.       if (b->address == NULL || !b->inserted)
  319.     continue;
  320.       else if (b->address + memory_breakpoint_size <= memaddr)
  321.     /* The breakpoint is entirely before the chunk of memory
  322.        we are reading.  */
  323.     continue;
  324.       else if (b->address >= memaddr + len)
  325.     /* The breakpoint is entirely after the chunk of memory we
  326.        are reading.  */
  327.     continue;
  328.       else
  329.     {
  330.       /* Copy the breakpoint from the shadow contents, and recurse
  331.          for the things before and after.  */
  332.       
  333.       /* Addresses and length of the part of the breakpoint that
  334.          we need to copy.  */
  335.       CORE_ADDR membpt = b->address;
  336.       unsigned int bptlen = memory_breakpoint_size;
  337.       /* Offset within shadow_contents.  */
  338.       int bptoffset = 0;
  339.       
  340.       if (membpt < memaddr)
  341.         {
  342.           /* Only copy the second part of the breakpoint.  */
  343.           bptlen -= memaddr - membpt;
  344.           bptoffset = memaddr - membpt;
  345.           membpt = memaddr;
  346.         }
  347.  
  348.       if (membpt + bptlen > memaddr + len)
  349.         {
  350.           /* Only copy the first part of the breakpoint.  */
  351.           bptlen -= (membpt + bptlen) - (memaddr + len);
  352.         }
  353.  
  354.       bcopy (b->shadow_contents + bptoffset,
  355.          myaddr + membpt - memaddr, bptlen);
  356.  
  357.       if (membpt > memaddr)
  358.         {
  359.           /* Copy the section of memory before the breakpoint.  */
  360.           status = read_memory_nobpt (memaddr, myaddr, membpt - memaddr);
  361.           if (status != 0)
  362.         return status;
  363.         }
  364.  
  365.       if (membpt + bptlen < memaddr + len)
  366.         {
  367.           /* Copy the section of memory after the breakpoint.  */
  368.           status = read_memory_nobpt
  369.         (membpt + bptlen,
  370.          myaddr + membpt + bptlen - memaddr,
  371.          memaddr + len - (membpt + bptlen));
  372.           if (status != 0)
  373.         return status;
  374.         }
  375.       return 0;
  376.     }
  377.     }
  378.   /* Nothing overlaps.  Just call read_memory_noerr.  */
  379.   return target_read_memory (memaddr, myaddr, len);
  380. }
  381.  
  382. /* insert_breakpoints is used when starting or continuing the program.
  383.    remove_breakpoints is used when the program stops.
  384.    Both return zero if successful,
  385.    or an `errno' value if could not write the inferior.  */
  386.  
  387. int
  388. insert_breakpoints ()
  389. {
  390.   register struct breakpoint *b;
  391.   int val = 0;
  392.   int disabled_breaks = 0;
  393.  
  394.   ALL_BREAKPOINTS (b)
  395.     if (b->address != NULL
  396.     && b->enable != disabled
  397.     && ! b->inserted
  398.     && ! b->duplicate)
  399.       {
  400.     val = target_insert_breakpoint(b->address, b->shadow_contents);
  401.     if (val)
  402.       {
  403.         /* Can't set the breakpoint.  */
  404. #if defined (DISABLE_UNSETTABLE_BREAK)
  405.         if (DISABLE_UNSETTABLE_BREAK (b->address))
  406.           {
  407.         val = 0;
  408.         b->enable = disabled;
  409.         if (!disabled_breaks)
  410.           {
  411.             fprintf (stderr,
  412.              "Cannot insert breakpoint %d:\n", b->number);
  413.             printf_filtered ("Disabling shared library breakpoints:\n");
  414.           }
  415.         disabled_breaks = 1;
  416.         printf_filtered ("%d ", b->number);
  417.           }
  418.         else
  419. #endif
  420.           {
  421.         fprintf (stderr, "Cannot insert breakpoint %d:\n", b->number);
  422. #ifdef ONE_PROCESS_WRITETEXT
  423.         fprintf (stderr,
  424.           "The same program may be running in another process.\n");
  425. #endif
  426.         memory_error (val, b->address);    /* which bombs us out */
  427.           }
  428.       }
  429.     else
  430.       b->inserted = 1;
  431.       }
  432.   if (disabled_breaks)
  433.     printf_filtered ("\n");
  434.   return val;
  435. }
  436.  
  437. int
  438. remove_breakpoints ()
  439. {
  440.   register struct breakpoint *b;
  441.   int val;
  442.  
  443. #ifdef BREAKPOINT_DEBUG
  444.   printf ("Removing breakpoints.\n");
  445. #endif /* BREAKPOINT_DEBUG */
  446.  
  447.   ALL_BREAKPOINTS (b)
  448.     if (b->address != NULL && b->inserted)
  449.       {
  450.     val = target_remove_breakpoint(b->address, b->shadow_contents);
  451.     if (val)
  452.       return val;
  453.     b->inserted = 0;
  454. #ifdef BREAKPOINT_DEBUG
  455.     printf ("Removed breakpoint at %s",
  456.         local_hex_string(b->address));
  457.     printf (", shadow %s",
  458.         local_hex_string(b->shadow_contents[0]));
  459.     printf (", %s.\n",
  460.         local_hex_string(b->shadow_contents[1]));
  461. #endif /* BREAKPOINT_DEBUG */
  462.       }
  463.  
  464.   return 0;
  465. }
  466.  
  467. /* Clear the "inserted" flag in all breakpoints.
  468.    This is done when the inferior is loaded.  */
  469.  
  470. void
  471. mark_breakpoints_out ()
  472. {
  473.   register struct breakpoint *b;
  474.  
  475.   ALL_BREAKPOINTS (b)
  476.     b->inserted = 0;
  477. }
  478.  
  479. /* breakpoint_here_p (PC) returns 1 if an enabled breakpoint exists at PC.
  480.    When continuing from a location with a breakpoint,
  481.    we actually single step once before calling insert_breakpoints.  */
  482.  
  483. int
  484. breakpoint_here_p (pc)
  485.      CORE_ADDR pc;
  486. {
  487.   register struct breakpoint *b;
  488.  
  489.   ALL_BREAKPOINTS (b)
  490.     if (b->enable != disabled && b->address == pc)
  491.       return 1;
  492.  
  493.   return 0;
  494. }
  495.  
  496. /* bpstat stuff.  External routines' interfaces are documented
  497.    in breakpoint.h.  */
  498. void
  499. bpstat_clear (bsp)
  500.      bpstat *bsp;
  501. {
  502.   bpstat p;
  503.   bpstat q;
  504.  
  505.   if (bsp == 0)
  506.     return;
  507.   p = *bsp;
  508.   while (p != NULL)
  509.     {
  510.       q = p->next;
  511.       if (p->old_val != NULL)
  512.     value_free (p->old_val);
  513.       free (p);
  514.       p = q;
  515.     }
  516.   *bsp = NULL;
  517. }
  518.  
  519. bpstat
  520. bpstat_copy (bs)
  521.      bpstat bs;
  522. {
  523.   bpstat p = NULL;
  524.   bpstat tmp;
  525.   bpstat retval;
  526.  
  527.   if (bs == NULL)
  528.     return bs;
  529.  
  530.   for (; bs != NULL; bs = bs->next)
  531.     {
  532.       tmp = (bpstat) xmalloc (sizeof (*tmp));
  533.       bcopy (bs, tmp, sizeof (*tmp));
  534.       if (p == NULL)
  535.     /* This is the first thing in the chain.  */
  536.     retval = tmp;
  537.       else
  538.     p->next = tmp;
  539.       p = tmp;
  540.     }
  541.   p->next = NULL;
  542.   return retval;
  543. }
  544.  
  545. int
  546. bpstat_num (bsp)
  547.      bpstat *bsp;
  548. {
  549.   struct breakpoint *b;
  550.  
  551.   if ((*bsp) == NULL)
  552.     return 0;            /* No more breakpoint values */
  553.   else
  554.     {
  555.       b = (*bsp)->breakpoint_at;
  556.       *bsp = (*bsp)->next;
  557.       if (b == NULL)
  558.     return -1;        /* breakpoint that's been deleted since */
  559.       else
  560.         return b->number;    /* We have its number */
  561.     }
  562. }
  563.  
  564. void
  565. bpstat_clear_actions (bs)
  566.      bpstat bs;
  567. {
  568.   for (; bs != NULL; bs = bs->next)
  569.     {
  570.       bs->commands = NULL;
  571.       if (bs->old_val != NULL)
  572.     {
  573.       value_free (bs->old_val);
  574.       bs->old_val = NULL;
  575.     }
  576.     }
  577. }
  578.  
  579. /* Stub for cleaning up our state if we error-out of a breakpoint command */
  580. /* ARGSUSED */
  581. static void
  582. cleanup_executing_breakpoints (ignore)
  583.      int ignore;
  584. {
  585.   executing_breakpoint_commands = 0;
  586. }
  587.  
  588. /* Execute all the commands associated with all the breakpoints at this
  589.    location.  Any of these commands could cause the process to proceed
  590.    beyond this point, etc.  We look out for such changes by checking
  591.    the global "breakpoint_proceeded" after each command.  */
  592. void
  593. bpstat_do_actions (bsp)
  594.      bpstat *bsp;
  595. {
  596.   bpstat bs;
  597.   struct cleanup *old_chain;
  598.  
  599.   executing_breakpoint_commands = 1;
  600.   old_chain = make_cleanup (cleanup_executing_breakpoints, 0);
  601.  
  602. top:
  603.   bs = *bsp;
  604.  
  605.   breakpoint_proceeded = 0;
  606.   for (; bs != NULL; bs = bs->next)
  607.     {
  608.       while (bs->commands)
  609.     {
  610.       char *line = bs->commands->line;
  611.       bs->commands = bs->commands->next;
  612.       execute_command (line, 0);
  613.       /* If the inferior is proceeded by the command, bomb out now.
  614.          The bpstat chain has been blown away by wait_for_inferior.
  615.          But since execution has stopped again, there is a new bpstat
  616.          to look at, so start over.  */
  617.       if (breakpoint_proceeded)
  618.         goto top;
  619.     }
  620.     }
  621.   clear_momentary_breakpoints ();
  622.  
  623.   executing_breakpoint_commands = 0;
  624.   discard_cleanups (old_chain);
  625. }
  626.  
  627. int
  628. bpstat_print (bs)
  629.      bpstat bs;
  630. {
  631.   /* bs->breakpoint_at can be NULL if it was a momentary breakpoint
  632.      which has since been deleted.  */
  633.   if (bs == NULL || bs->breakpoint_at == NULL)
  634.     return 0;
  635.   
  636.   /* If bpstat_stop_status says don't print, OK, we won't.  An example
  637.      circumstance is when we single-stepped for both a watchpoint and
  638.      for a "stepi" instruction.  The bpstat says that the watchpoint
  639.      explains the stop, but we shouldn't print because the watchpoint's
  640.      value didn't change -- and the real reason we are stopping here
  641.      rather than continuing to step (as the watchpoint would've had us do)
  642.      is because of the "stepi".  */
  643.   if (!bs->print)
  644.     return 0;
  645.  
  646.   if (bs->breakpoint_at->address != NULL)
  647.     {
  648.       /* I think the user probably only wants to see one breakpoint
  649.      number, not all of them.  */
  650.       printf_filtered ("\nBreakpoint %d, ", bs->breakpoint_at->number);
  651.       return 0;
  652.     }
  653.       
  654.   if (bs->old_val != NULL)
  655.     {
  656.       printf_filtered ("\nWatchpoint %d, ", bs->breakpoint_at->number);
  657.       print_expression (bs->breakpoint_at->exp, stdout);
  658.       printf_filtered ("\nOld value = ");
  659.       value_print (bs->old_val, stdout, 0, Val_pretty_default);
  660.       printf_filtered ("\nNew value = ");
  661.       value_print (bs->breakpoint_at->val, stdout, 0,
  662.            Val_pretty_default);
  663.       printf_filtered ("\n");
  664.       value_free (bs->old_val);
  665.       bs->old_val = NULL;
  666.       return 1;
  667.     }
  668.  
  669.   /* Maybe another breakpoint in the chain caused us to stop.
  670.      (Currently all watchpoints go on the bpstat whether hit or
  671.      not.  That probably could (should) be changed, provided care is taken
  672.      with respect to bpstat_explains_signal).  */
  673.   if (bs->next)
  674.     return bpstat_print (bs->next);
  675.  
  676.   fprintf_filtered (stderr, "gdb internal error: in bpstat_print\n");
  677.   return 0;
  678. }
  679.  
  680. /* Evaluate the expression EXP and return 1 if value is zero.
  681.    This is used inside a catch_errors to evaluate the breakpoint condition. 
  682.    The argument is a "struct expression *" that has been cast to char * to 
  683.    make it pass through catch_errors.  */
  684.  
  685. static int
  686. breakpoint_cond_eval (exp)
  687.      char *exp;
  688. {
  689.   return !value_true (evaluate_expression ((struct expression *)exp));
  690. }
  691.  
  692. /* Allocate a new bpstat and chain it to the current one.  */
  693.  
  694. static bpstat
  695. bpstat_alloc (b, cbs)
  696.      register struct breakpoint *b;
  697.      bpstat cbs;            /* Current "bs" value */
  698. {
  699.   bpstat bs;
  700.  
  701.   bs = (bpstat) xmalloc (sizeof (*bs));
  702.   cbs->next = bs;
  703.   bs->breakpoint_at = b;
  704.   /* If the condition is false, etc., don't do the commands.  */
  705.   bs->commands = NULL;
  706.   bs->momentary = b->number == -3;
  707.   bs->old_val = NULL;
  708.   return bs;
  709. }
  710.  
  711. /* Determine whether we stopped at a breakpoint, etc, or whether we
  712.    don't understand this stop.  Result is a chain of bpstat's such that:
  713.  
  714.     if we don't understand the stop, the result is a null pointer.
  715.  
  716.     if we understand why we stopped, the result is not null, and
  717.     the first element of the chain contains summary "stop" and
  718.     "print" flags for the whole chain.
  719.  
  720.     Each element of the chain refers to a particular breakpoint or
  721.     watchpoint at which we have stopped.  (We may have stopped for
  722.     several reasons.)
  723.  
  724.     Each element of the chain has valid next, breakpoint_at,
  725.     commands, FIXME??? fields.
  726.  
  727.  */
  728.  
  729.     
  730. bpstat
  731. bpstat_stop_status (pc, frame_address)
  732.      CORE_ADDR *pc;
  733.      FRAME_ADDR frame_address;
  734. {
  735.   register struct breakpoint *b;
  736.   int stop = 0;
  737.   int print = 0;
  738.   CORE_ADDR bp_addr;
  739. #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
  740.   /* True if we've hit a breakpoint (as opposed to a watchpoint).  */
  741.   int real_breakpoint = 0;
  742. #endif
  743.   /* Root of the chain of bpstat's */
  744.   struct bpstat__struct root_bs[1];
  745.   /* Pointer to the last thing in the chain currently.  */
  746.   bpstat bs = root_bs;
  747.  
  748.   /* Get the address where the breakpoint would have been.  */
  749.   bp_addr = *pc - DECR_PC_AFTER_BREAK;
  750.  
  751.   ALL_BREAKPOINTS (b)
  752.     {
  753.       int this_bp_stop;
  754.       int this_bp_print;
  755.  
  756.       if (b->enable == disabled)
  757.     continue;
  758.       if (b->address != NULL && b->address != bp_addr)
  759.     continue;
  760.  
  761.       bs = bpstat_alloc (b, bs);    /* Alloc a bpstat to explain stop */
  762.  
  763.       this_bp_stop = 1;
  764.       this_bp_print = 1;
  765.  
  766.       if (b->exp != NULL)        /* Watchpoint */
  767.     {
  768.       int within_current_scope;
  769.       if (b->exp_valid_block != NULL)
  770.         within_current_scope =
  771.           contained_in (get_selected_block (), b->exp_valid_block);
  772.       else
  773.         within_current_scope = 1;
  774.  
  775.       if (within_current_scope)
  776.         {
  777.           /* We use value_{,free_to_}mark because it could be a
  778.          *long* time before we return to the command level and
  779.          call free_all_values.  */
  780.  
  781.           value mark = value_mark ();
  782.           value new_val = evaluate_expression (b->exp);
  783.           if (!value_equal (b->val, new_val))
  784.         {
  785.           release_value (new_val);
  786.           value_free_to_mark (mark);
  787.           bs->old_val = b->val;
  788.           b->val = new_val;
  789.           /* We will stop here */
  790.         }
  791.           else
  792.         {
  793.           /* Nothing changed, don't do anything.  */
  794.           value_free_to_mark (mark);
  795.           continue;
  796.           /* We won't stop here */
  797.         }
  798.         }
  799.       else
  800.         {
  801.           /* This seems like the only logical thing to do because
  802.          if we temporarily ignored the watchpoint, then when
  803.          we reenter the block in which it is valid it contains
  804.          garbage (in the case of a function, it may have two
  805.          garbage values, one before and one after the prologue).
  806.          So we can't even detect the first assignment to it and
  807.          watch after that (since the garbage may or may not equal
  808.          the first value assigned).  */
  809.           b->enable = disabled;
  810.           printf_filtered ("\
  811. Watchpoint %d disabled because the program has left the block in\n\
  812. which its expression is valid.\n", b->number);
  813.           /* We won't stop here */
  814.           /* FIXME, maybe we should stop here!!! */
  815.           continue;
  816.         }
  817.     }
  818. #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
  819.       else
  820.     real_breakpoint = 1;
  821. #endif
  822.  
  823.       if (b->frame && b->frame != frame_address)
  824.     this_bp_stop = 0;
  825.       else
  826.     {
  827.       int value_is_zero;
  828.  
  829.       if (b->cond)
  830.         {
  831.           /* Need to select the frame, with all that implies
  832.          so that the conditions will have the right context.  */
  833.           select_frame (get_current_frame (), 0);
  834.           value_is_zero
  835.         = catch_errors (breakpoint_cond_eval, (char *)(b->cond),
  836.                 "Error in testing breakpoint condition:\n");
  837.                 /* FIXME-someday, should give breakpoint # */
  838.           free_all_values ();
  839.         }
  840.       if (b->cond && value_is_zero)
  841.         {
  842.           this_bp_stop = 0;
  843.         }
  844.       else if (b->ignore_count > 0)
  845.         {
  846.           b->ignore_count--;
  847.           this_bp_stop = 0;
  848.         }
  849.       else
  850.         {
  851.           /* We will stop here */
  852.           if (b->enable == temporary)
  853.         b->enable = disabled;
  854.           bs->commands = b->commands;
  855.           if (b->silent)
  856.         this_bp_print = 0;
  857.           if (bs->commands && !strcmp ("silent", bs->commands->line))
  858.         {
  859.           bs->commands = bs->commands->next;
  860.           this_bp_print = 0;
  861.         }
  862.         }
  863.     }
  864.       if (this_bp_stop)
  865.     stop = 1;
  866.       if (this_bp_print)
  867.     print = 1;
  868.     }
  869.  
  870.   bs->next = NULL;        /* Terminate the chain */
  871.   bs = root_bs->next;        /* Re-grab the head of the chain */
  872.   if (bs)
  873.     {
  874.       bs->stop = stop;
  875.       bs->print = print;
  876. #if DECR_PC_AFTER_BREAK != 0 || defined (SHIFT_INST_REGS)
  877.       if (real_breakpoint)
  878.     {
  879.       *pc = bp_addr;
  880. #if defined (SHIFT_INST_REGS)
  881.       {
  882.         CORE_ADDR pc = read_register (PC_REGNUM);
  883.         CORE_ADDR npc = read_register (NPC_REGNUM);
  884.         if (pc != npc)
  885.           {
  886.         write_register (NNPC_REGNUM, npc);
  887.         write_register (NPC_REGNUM, pc);
  888.           }
  889.       }
  890. #else /* No SHIFT_INST_REGS.  */
  891.       write_pc (bp_addr);
  892. #endif /* No SHIFT_INST_REGS.  */
  893.     }
  894. #endif /* DECR_PC_AFTER_BREAK != 0.  */
  895.     }
  896.   return bs;
  897. }
  898.  
  899. int 
  900. bpstat_should_step ()
  901. {
  902.   struct breakpoint *b;
  903.   ALL_BREAKPOINTS (b)
  904.     if (b->enable != disabled && b->exp != NULL)
  905.       return 1;
  906.   return 0;
  907. }
  908.  
  909. /* Print information on breakpoint number BNUM, or -1 if all.
  910.    If WATCHPOINTS is zero, process only breakpoints; if WATCHPOINTS
  911.    is nonzero, process only watchpoints.  */
  912.  
  913. static void
  914. breakpoint_1 (bnum, watchpoints)
  915.      int bnum;
  916.      int watchpoints;
  917. {
  918.   register struct breakpoint *b;
  919.   register struct command_line *l;
  920.   register struct symbol *sym;
  921.   CORE_ADDR last_addr = (CORE_ADDR)-1;
  922.   int header_printed = 0;
  923.   
  924.   ALL_BREAKPOINTS (b)
  925.     if (bnum == -1 || bnum == b->number)
  926.       {
  927.     if (b->address == NULL && !watchpoints)
  928.       {
  929.         if (bnum == -1)
  930.           continue;
  931.         error ("That is a watchpoint, not a breakpoint.");
  932.       }
  933.     if (b->address != NULL && watchpoints)
  934.       {
  935.         if (bnum == -1)
  936.           continue;
  937.         error ("That is a breakpoint, not a watchpoint.");
  938.       }
  939.  
  940.     if (!header_printed)
  941.       {
  942.         if (watchpoints)
  943.           printf_filtered ("    Enb   Expression\n");
  944.         else if (addressprint)
  945.           printf_filtered ("    Enb   Address    Where\n");
  946.         else
  947.           printf_filtered ("    Enb   Where\n");
  948.         header_printed = 1;
  949.       }
  950.  
  951.     printf_filtered ("#%-3d %c ", b->number, "nyod"[(int) b->enable]);
  952.     if (b->address == NULL) {
  953.       printf_filtered (" ");
  954.       print_expression (b->exp, stdout);
  955.     } else {
  956.         if (addressprint)
  957.           printf_filtered (" %s ", local_hex_string_custom(b->address, "08"));
  958.  
  959.         last_addr = b->address;
  960.         if (b->symtab)
  961.           {
  962.         sym = find_pc_function (b->address);
  963.         if (sym)
  964.           {
  965.             fputs_filtered (" in ", stdout);
  966.             fputs_demangled (SYMBOL_NAME (sym), stdout, 1);
  967.             fputs_filtered (" at ", stdout);
  968.           }
  969.         fputs_filtered (b->symtab->filename, stdout);
  970.         printf_filtered (":%d", b->line_number);
  971.           }
  972.         else
  973.           print_address_symbolic (b->address, stdout, demangle, " ");
  974.       }
  975.  
  976.     printf_filtered ("\n");
  977.  
  978.     if (b->frame)
  979.       printf_filtered ("\tstop only in stack frame at %s\n",
  980.                local_hex_string(b->frame));
  981.     if (b->cond)
  982.       {
  983.         printf_filtered ("\tstop only if ");
  984.         print_expression (b->cond, stdout);
  985.         printf_filtered ("\n");
  986.       }
  987.     if (b->ignore_count)
  988.       printf_filtered ("\tignore next %d hits\n", b->ignore_count);
  989.     if ((l = b->commands))
  990.       while (l)
  991.         {
  992.           fputs_filtered ("\t", stdout);
  993.           fputs_filtered (l->line, stdout);
  994.           fputs_filtered ("\n", stdout);
  995.           l = l->next;
  996.         }
  997.       }
  998.  
  999.   if (!header_printed)
  1000.     {
  1001.       char *which = watchpoints ? "watch" : "break";
  1002.       if (bnum == -1)
  1003.     printf_filtered ("No %spoints.\n", which);
  1004.       else
  1005.     printf_filtered ("No %spoint numbered %d.\n", which, bnum);
  1006.     }
  1007.  
  1008.   /* Compare against (CORE_ADDR)-1 in case some compiler decides
  1009.      that a comparison of an unsigned with -1 is always false.  */
  1010.   if (last_addr != (CORE_ADDR)-1)
  1011.     set_next_address (last_addr);
  1012. }
  1013.  
  1014. /* ARGSUSED */
  1015. static void
  1016. breakpoints_info (bnum_exp, from_tty)
  1017.      char *bnum_exp;
  1018.      int from_tty;
  1019. {
  1020.   int bnum = -1;
  1021.  
  1022.   if (bnum_exp)
  1023.     bnum = parse_and_eval_address (bnum_exp);
  1024.  
  1025.   breakpoint_1 (bnum, 0);
  1026. }
  1027.  
  1028. /* ARGSUSED */
  1029. static void
  1030. watchpoints_info (bnum_exp, from_tty)
  1031.      char *bnum_exp;
  1032.      int from_tty;
  1033. {
  1034.   int bnum = -1;
  1035.  
  1036.   if (bnum_exp)
  1037.     bnum = parse_and_eval_address (bnum_exp);
  1038.  
  1039.   breakpoint_1 (bnum, 1);
  1040. }
  1041.  
  1042. /* Print a message describing any breakpoints set at PC.  */
  1043.  
  1044. static void
  1045. describe_other_breakpoints (pc)
  1046.      register CORE_ADDR pc;
  1047. {
  1048.   register int others = 0;
  1049.   register struct breakpoint *b;
  1050.  
  1051.   ALL_BREAKPOINTS (b)
  1052.     if (b->address == pc)
  1053.       others++;
  1054.   if (others > 0)
  1055.     {
  1056.       printf ("Note: breakpoint%s ", (others > 1) ? "s" : "");
  1057.       ALL_BREAKPOINTS (b)
  1058.     if (b->address == pc)
  1059.       {
  1060.         others--;
  1061.         printf ("%d%s%s ",
  1062.             b->number,
  1063.             (b->enable == disabled) ? " (disabled)" : "",
  1064.             (others > 1) ? "," : ((others == 1) ? " and" : ""));
  1065.       }
  1066.       printf ("also set at pc %s.\n", local_hex_string(pc));
  1067.     }
  1068. }
  1069.  
  1070. /* Set the default place to put a breakpoint
  1071.    for the `break' command with no arguments.  */
  1072.  
  1073. void
  1074. set_default_breakpoint (valid, addr, symtab, line)
  1075.      int valid;
  1076.      CORE_ADDR addr;
  1077.      struct symtab *symtab;
  1078.      int line;
  1079. {
  1080.   default_breakpoint_valid = valid;
  1081.   default_breakpoint_address = addr;
  1082.   default_breakpoint_symtab = symtab;
  1083.   default_breakpoint_line = line;
  1084. }
  1085.  
  1086. /* Rescan breakpoints at address ADDRESS,
  1087.    marking the first one as "first" and any others as "duplicates".
  1088.    This is so that the bpt instruction is only inserted once.  */
  1089.  
  1090. static void
  1091. check_duplicates (address)
  1092.      CORE_ADDR address;
  1093. {
  1094.   register struct breakpoint *b;
  1095.   register int count = 0;
  1096.  
  1097.   if (address == NULL)        /* Watchpoints are uninteresting */
  1098.     return;
  1099.  
  1100.   ALL_BREAKPOINTS (b)
  1101.     if (b->enable != disabled && b->address == address)
  1102.       {
  1103.     count++;
  1104.     b->duplicate = count > 1;
  1105.       }
  1106. }
  1107.  
  1108. /* Low level routine to set a breakpoint.
  1109.    Takes as args the three things that every breakpoint must have.
  1110.    Returns the breakpoint object so caller can set other things.
  1111.    Does not set the breakpoint number!
  1112.    Does not print anything.
  1113.  
  1114.    ==> This routine should not be called if there is a chance of later
  1115.    error(); otherwise it leaves a bogus breakpoint on the chain.  Validate
  1116.    your arguments BEFORE calling this routine!  */
  1117.  
  1118. static struct breakpoint *
  1119. set_raw_breakpoint (sal)
  1120.      struct symtab_and_line sal;
  1121. {
  1122.   register struct breakpoint *b, *b1;
  1123.  
  1124.   b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint));
  1125.   bzero (b, sizeof *b);
  1126.   b->address = sal.pc;
  1127.   b->symtab = sal.symtab;
  1128.   b->line_number = sal.line;
  1129.   b->enable = enabled;
  1130.   b->next = 0;
  1131.   b->silent = 0;
  1132.   b->ignore_count = 0;
  1133.   b->commands = NULL;
  1134.   b->frame = NULL;
  1135.  
  1136.   /* Add this breakpoint to the end of the chain
  1137.      so that a list of breakpoints will come out in order
  1138.      of increasing numbers.  */
  1139.  
  1140.   b1 = breakpoint_chain;
  1141.   if (b1 == 0)
  1142.     breakpoint_chain = b;
  1143.   else
  1144.     {
  1145.       while (b1->next)
  1146.     b1 = b1->next;
  1147.       b1->next = b;
  1148.     }
  1149.  
  1150.   check_duplicates (sal.pc);
  1151.  
  1152.   return b;
  1153. }
  1154.  
  1155. /* Set a breakpoint that will evaporate an end of command
  1156.    at address specified by SAL.
  1157.    Restrict it to frame FRAME if FRAME is nonzero.  */
  1158.  
  1159. void
  1160. set_momentary_breakpoint (sal, frame)
  1161.      struct symtab_and_line sal;
  1162.      FRAME frame;
  1163. {
  1164.   register struct breakpoint *b;
  1165.   b = set_raw_breakpoint (sal);
  1166.   b->number = -3;
  1167.   b->enable = delete;
  1168.   b->frame = (frame ? FRAME_FP (frame) : 0);
  1169. }
  1170.  
  1171. void
  1172. clear_momentary_breakpoints ()
  1173. {
  1174.   register struct breakpoint *b;
  1175.   ALL_BREAKPOINTS (b)
  1176.     if (b->number == -3)
  1177.       {
  1178.     delete_breakpoint (b);
  1179.     break;
  1180.       }
  1181. }
  1182.  
  1183. /* Tell the user we have just set a breakpoint B.  */
  1184. static void
  1185. mention (b)
  1186.      struct breakpoint *b;
  1187. {
  1188.   if (b->exp)
  1189.     {
  1190.       printf_filtered ("Watchpoint %d: ", b->number);
  1191.       print_expression (b->exp, stdout);
  1192.     }
  1193.   else
  1194.     {
  1195.       printf_filtered ("Breakpoint %d at %s", b->number,
  1196.                local_hex_string(b->address));
  1197.       if (b->symtab)
  1198.     printf_filtered (": file %s, line %d.",
  1199.              b->symtab->filename, b->line_number);
  1200.     }
  1201.   printf_filtered ("\n");
  1202. }
  1203.  
  1204. #if 0
  1205. /* Nobody calls this currently. */
  1206. /* Set a breakpoint from a symtab and line.
  1207.    If TEMPFLAG is nonzero, it is a temporary breakpoint.
  1208.    ADDR_STRING is a malloc'd string holding the name of where we are
  1209.    setting the breakpoint.  This is used later to re-set it after the
  1210.    program is relinked and symbols are reloaded.
  1211.    Print the same confirmation messages that the breakpoint command prints.  */
  1212.  
  1213. void
  1214. set_breakpoint (s, line, tempflag, addr_string)
  1215.      struct symtab *s;
  1216.      int line;
  1217.      int tempflag;
  1218.      char *addr_string;
  1219. {
  1220.   register struct breakpoint *b;
  1221.   struct symtab_and_line sal;
  1222.   
  1223.   sal.symtab = s;
  1224.   sal.line = line;
  1225.   sal.pc = find_line_pc (sal.symtab, sal.line);
  1226.   if (sal.pc == 0)
  1227.     error ("No line %d in file \"%s\".\n", sal.line, sal.symtab->filename);
  1228.   else
  1229.     {
  1230.       describe_other_breakpoints (sal.pc);
  1231.  
  1232.       b = set_raw_breakpoint (sal);
  1233.       set_breakpoint_count (breakpoint_count + 1);
  1234.       b->number = breakpoint_count;
  1235.       b->cond = 0;
  1236.       b->addr_string = addr_string;
  1237.       if (tempflag)
  1238.     b->enable = temporary;
  1239.  
  1240.       mention (b);
  1241.     }
  1242. }
  1243. #endif
  1244.  
  1245. /* Set a breakpoint according to ARG (function, linenum or *address)
  1246.    and make it temporary if TEMPFLAG is nonzero. */
  1247.  
  1248. static void
  1249. break_command_1 (arg, tempflag, from_tty)
  1250.      char *arg;
  1251.      int tempflag, from_tty;
  1252. {
  1253.   struct symtabs_and_lines sals;
  1254.   struct symtab_and_line sal;
  1255.   register struct expression *cond = 0;
  1256.   register struct breakpoint *b;
  1257.  
  1258.   /* Pointers in arg to the start, and one past the end, of the condition.  */
  1259.   char *cond_start = NULL;
  1260.   char *cond_end;
  1261.   /* Pointers in arg to the start, and one past the end,
  1262.      of the address part.  */
  1263.   char *addr_start = NULL;
  1264.   char *addr_end;
  1265.   
  1266.   int i;
  1267.   CORE_ADDR pc;
  1268.  
  1269.   sals.sals = NULL;
  1270.   sals.nelts = 0;
  1271.  
  1272.   sal.line = sal.pc = sal.end = 0;
  1273.   sal.symtab = 0;
  1274.  
  1275.   /* If no arg given, or if first arg is 'if ', use the default breakpoint. */
  1276.  
  1277.   if (!arg || (arg[0] == 'i' && arg[1] == 'f' 
  1278.            && (arg[2] == ' ' || arg[2] == '\t')))
  1279.     {
  1280.       if (default_breakpoint_valid)
  1281.     {
  1282.       sals.sals = (struct symtab_and_line *) 
  1283.         xmalloc (sizeof (struct symtab_and_line));
  1284.       sal.pc = default_breakpoint_address;
  1285.       sal.line = default_breakpoint_line;
  1286.       sal.symtab = default_breakpoint_symtab;
  1287.       sals.sals[0] = sal;
  1288.       sals.nelts = 1;
  1289.     }
  1290.       else
  1291.     error ("No default breakpoint address now.");
  1292.     }
  1293.   else
  1294.     {
  1295.       addr_start = arg;
  1296.  
  1297.       /* Force almost all breakpoints to be in terms of the
  1298.      current_source_symtab (which is decode_line_1's default).  This
  1299.      should produce the results we want almost all of the time while
  1300.      leaving default_breakpoint_* alone.  */
  1301.       if (default_breakpoint_valid
  1302.       && (!current_source_symtab
  1303.           || (arg && (*arg == '+' || *arg == '-'))))
  1304.     sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
  1305.                   default_breakpoint_line);
  1306.       else
  1307.     sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
  1308.  
  1309.       addr_end = arg;
  1310.     }
  1311.   
  1312.   if (! sals.nelts) 
  1313.     return;
  1314.  
  1315.   for (i = 0; i < sals.nelts; i++)
  1316.     {
  1317.       sal = sals.sals[i];
  1318.       if (sal.pc == 0 && sal.symtab != 0)
  1319.     {
  1320.       pc = find_line_pc (sal.symtab, sal.line);
  1321.       if (pc == 0)
  1322.         error ("No line %d in file \"%s\".",
  1323.            sal.line, sal.symtab->filename);
  1324.     }
  1325.       else 
  1326.     pc = sal.pc;
  1327.       
  1328.       while (arg && *arg)
  1329.     {
  1330.       if (arg[0] == 'i' && arg[1] == 'f'
  1331.           && (arg[2] == ' ' || arg[2] == '\t'))
  1332.         {
  1333.           arg += 2;
  1334.           cond_start = arg;
  1335.           cond = parse_exp_1 (&arg, block_for_pc (pc), 0);
  1336.           cond_end = arg;
  1337.         }
  1338.       else
  1339.         error ("Junk at end of arguments.");
  1340.     }
  1341.       sals.sals[i].pc = pc;
  1342.     }
  1343.  
  1344.   for (i = 0; i < sals.nelts; i++)
  1345.     {
  1346.       sal = sals.sals[i];
  1347.  
  1348.       if (from_tty)
  1349.     describe_other_breakpoints (sal.pc);
  1350.  
  1351.       b = set_raw_breakpoint (sal);
  1352.       set_breakpoint_count (breakpoint_count + 1);
  1353.       b->number = breakpoint_count;
  1354.       b->cond = cond;
  1355.       
  1356.       if (addr_start)
  1357.     b->addr_string = savestring (addr_start, addr_end - addr_start);
  1358.       if (cond_start)
  1359.     b->cond_string = savestring (cond_start, cond_end - cond_start);
  1360.                      
  1361.       if (tempflag)
  1362.     b->enable = temporary;
  1363.  
  1364.       mention (b);
  1365.     }
  1366.  
  1367.   if (sals.nelts > 1)
  1368.     {
  1369.       printf ("Multiple breakpoints were set.\n");
  1370.       printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
  1371.     }
  1372.   free (sals.sals);
  1373. }
  1374.  
  1375. void
  1376. break_command (arg, from_tty)
  1377.      char *arg;
  1378.      int from_tty;
  1379. {
  1380.   break_command_1 (arg, 0, from_tty);
  1381. }
  1382.  
  1383. static void
  1384. tbreak_command (arg, from_tty)
  1385.      char *arg;
  1386.      int from_tty;
  1387. {
  1388.   break_command_1 (arg, 1, from_tty);
  1389. }
  1390.  
  1391. /* ARGSUSED */
  1392. static void
  1393. watch_command (arg, from_tty)
  1394.      char *arg;
  1395.      int from_tty;
  1396. {
  1397.   struct breakpoint *b;
  1398.   struct symtab_and_line sal;
  1399.   struct expression *exp;
  1400.   struct block *exp_valid_block;
  1401.   struct value *val;
  1402.  
  1403.   sal.pc = NULL;
  1404.   sal.symtab = NULL;
  1405.   sal.line = 0;
  1406.   
  1407.   /* Parse arguments.  */
  1408.   innermost_block = NULL;
  1409.   exp = parse_expression (arg);
  1410.   exp_valid_block = innermost_block;
  1411.   val = evaluate_expression (exp);
  1412.   release_value (val);
  1413.  
  1414.   /* Now set up the breakpoint.  */
  1415.   b = set_raw_breakpoint (sal);
  1416.   set_breakpoint_count (breakpoint_count + 1);
  1417.   b->number = breakpoint_count;
  1418.   b->exp = exp;
  1419.   b->exp_valid_block = exp_valid_block;
  1420.   b->val = val;
  1421.   b->cond = 0;
  1422.   b->cond_string = NULL;
  1423.   mention (b);
  1424. }
  1425.  
  1426. /*
  1427.  * Helper routine for the until_command routine in infcmd.c.  Here
  1428.  * because it uses the mechanisms of breakpoints.
  1429.  */
  1430. /* ARGSUSED */
  1431. void
  1432. until_break_command (arg, from_tty)
  1433.      char *arg;
  1434.      int from_tty;
  1435. {
  1436.   struct symtabs_and_lines sals;
  1437.   struct symtab_and_line sal;
  1438.   FRAME prev_frame = get_prev_frame (selected_frame);
  1439.  
  1440.   clear_proceed_status ();
  1441.  
  1442.   /* Set a breakpoint where the user wants it and at return from
  1443.      this function */
  1444.   
  1445.   if (default_breakpoint_valid)
  1446.     sals = decode_line_1 (&arg, 1, default_breakpoint_symtab,
  1447.               default_breakpoint_line);
  1448.   else
  1449.     sals = decode_line_1 (&arg, 1, (struct symtab *)NULL, 0);
  1450.   
  1451.   if (sals.nelts != 1)
  1452.     error ("Couldn't get information on specified line.");
  1453.   
  1454.   sal = sals.sals[0];
  1455.   free (sals.sals);        /* malloc'd, so freed */
  1456.   
  1457.   if (*arg)
  1458.     error ("Junk at end of arguments.");
  1459.   
  1460.   if (sal.pc == 0 && sal.symtab != 0)
  1461.     sal.pc = find_line_pc (sal.symtab, sal.line);
  1462.   
  1463.   if (sal.pc == 0)
  1464.     error ("No line %d in file \"%s\".", sal.line, sal.symtab->filename);
  1465.   
  1466.   set_momentary_breakpoint (sal, selected_frame);
  1467.   
  1468.   /* Keep within the current frame */
  1469.   
  1470.   if (prev_frame)
  1471.     {
  1472.       struct frame_info *fi;
  1473.       
  1474.       fi = get_frame_info (prev_frame);
  1475.       sal = find_pc_line (fi->pc, 0);
  1476.       sal.pc = fi->pc;
  1477.       set_momentary_breakpoint (sal, prev_frame);
  1478.     }
  1479.   
  1480.   proceed (-1, -1, 0);
  1481. }
  1482.  
  1483. #if 0
  1484. /* These aren't used; I don't konw what they were for.  */
  1485. /* Set a breakpoint at the catch clause for NAME.  */
  1486. static int
  1487. catch_breakpoint (name)
  1488.      char *name;
  1489. {
  1490. }
  1491.  
  1492. static int
  1493. disable_catch_breakpoint ()
  1494. {
  1495. }
  1496.  
  1497. static int
  1498. delete_catch_breakpoint ()
  1499. {
  1500. }
  1501.  
  1502. static int
  1503. enable_catch_breakpoint ()
  1504. {
  1505. }
  1506. #endif /* 0 */
  1507.  
  1508. struct sal_chain
  1509. {
  1510.   struct sal_chain *next;
  1511.   struct symtab_and_line sal;
  1512. };
  1513.  
  1514. #if 0
  1515. /* This isn't used; I don't know what it was for.  */
  1516. /* For each catch clause identified in ARGS, run FUNCTION
  1517.    with that clause as an argument.  */
  1518. static struct symtabs_and_lines
  1519. map_catch_names (args, function)
  1520.      char *args;
  1521.      int (*function)();
  1522. {
  1523.   register char *p = args;
  1524.   register char *p1;
  1525.   struct symtabs_and_lines sals;
  1526. #if 0
  1527.   struct sal_chain *sal_chain = 0;
  1528. #endif
  1529.  
  1530.   if (p == 0)
  1531.     error_no_arg ("one or more catch names");
  1532.  
  1533.   sals.nelts = 0;
  1534.   sals.sals = NULL;
  1535.  
  1536.   while (*p)
  1537.     {
  1538.       p1 = p;
  1539.       /* Don't swallow conditional part.  */
  1540.       if (p1[0] == 'i' && p1[1] == 'f'
  1541.       && (p1[2] == ' ' || p1[2] == '\t'))
  1542.     break;
  1543.  
  1544.       if (isalpha (*p1))
  1545.     {
  1546.       p1++;
  1547.       while (isalnum (*p1) || *p1 == '_' || *p1 == '$')
  1548.         p1++;
  1549.     }
  1550.  
  1551.       if (*p1 && *p1 != ' ' && *p1 != '\t')
  1552.     error ("Arguments must be catch names.");
  1553.  
  1554.       *p1 = 0;
  1555. #if 0
  1556.       if (function (p))
  1557.     {
  1558.       struct sal_chain *next
  1559.         = (struct sal_chain *)alloca (sizeof (struct sal_chain));
  1560.       next->next = sal_chain;
  1561.       next->sal = get_catch_sal (p);
  1562.       sal_chain = next;
  1563.       goto win;
  1564.     }
  1565. #endif
  1566.       printf ("No catch clause for exception %s.\n", p);
  1567. #if 0
  1568.     win:
  1569. #endif
  1570.       p = p1;
  1571.       while (*p == ' ' || *p == '\t') p++;
  1572.     }
  1573. }
  1574. #endif /* 0 */
  1575.  
  1576. /* This shares a lot of code with `print_frame_label_vars' from stack.c.  */
  1577.  
  1578. static struct symtabs_and_lines
  1579. get_catch_sals (this_level_only)
  1580.      int this_level_only;
  1581. {
  1582.   extern struct blockvector *blockvector_for_pc ();
  1583.   register struct blockvector *bl;
  1584.   register struct block *block;
  1585.   int index, have_default = 0;
  1586.   struct frame_info *fi;
  1587.   CORE_ADDR pc;
  1588.   struct symtabs_and_lines sals;
  1589.   struct sal_chain *sal_chain = 0;
  1590.   char *blocks_searched;
  1591.  
  1592.   /* Not sure whether an error message is always the correct response,
  1593.      but it's better than a core dump.  */
  1594.   if (selected_frame == NULL)
  1595.     error ("No selected frame.");
  1596.   block = get_frame_block (selected_frame);
  1597.   fi = get_frame_info (selected_frame);
  1598.   pc = fi->pc;
  1599.  
  1600.   sals.nelts = 0;
  1601.   sals.sals = NULL;
  1602.  
  1603.   if (block == 0)
  1604.     error ("No symbol table info available.\n");
  1605.  
  1606.   bl = blockvector_for_pc (BLOCK_END (block) - 4, &index);
  1607.   blocks_searched = (char *) alloca (BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
  1608.   bzero (blocks_searched, BLOCKVECTOR_NBLOCKS (bl) * sizeof (char));
  1609.  
  1610.   while (block != 0)
  1611.     {
  1612.       CORE_ADDR end = BLOCK_END (block) - 4;
  1613.       int last_index;
  1614.  
  1615.       if (bl != blockvector_for_pc (end, &index))
  1616.     error ("blockvector blotch");
  1617.       if (BLOCKVECTOR_BLOCK (bl, index) != block)
  1618.     error ("blockvector botch");
  1619.       last_index = BLOCKVECTOR_NBLOCKS (bl);
  1620.       index += 1;
  1621.  
  1622.       /* Don't print out blocks that have gone by.  */
  1623.       while (index < last_index
  1624.          && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < pc)
  1625.     index++;
  1626.  
  1627.       while (index < last_index
  1628.          && BLOCK_END (BLOCKVECTOR_BLOCK (bl, index)) < end)
  1629.     {
  1630.       if (blocks_searched[index] == 0)
  1631.         {
  1632.           struct block *b = BLOCKVECTOR_BLOCK (bl, index);
  1633.           int nsyms;
  1634.           register int i;
  1635.           register struct symbol *sym;
  1636.  
  1637.           nsyms = BLOCK_NSYMS (b);
  1638.  
  1639.           for (i = 0; i < nsyms; i++)
  1640.         {
  1641.           sym = BLOCK_SYM (b, i);
  1642.           if (! strcmp (SYMBOL_NAME (sym), "default"))
  1643.             {
  1644.               if (have_default)
  1645.             continue;
  1646.               have_default = 1;
  1647.             }
  1648.           if (SYMBOL_CLASS (sym) == LOC_LABEL)
  1649.             {
  1650.               struct sal_chain *next = (struct sal_chain *)
  1651.             alloca (sizeof (struct sal_chain));
  1652.               next->next = sal_chain;
  1653.               next->sal = find_pc_line (SYMBOL_VALUE_ADDRESS (sym), 0);
  1654.               sal_chain = next;
  1655.             }
  1656.         }
  1657.           blocks_searched[index] = 1;
  1658.         }
  1659.       index++;
  1660.     }
  1661.       if (have_default)
  1662.     break;
  1663.       if (sal_chain && this_level_only)
  1664.     break;
  1665.  
  1666.       /* After handling the function's top-level block, stop.
  1667.      Don't continue to its superblock, the block of
  1668.      per-file symbols.  */
  1669.       if (BLOCK_FUNCTION (block))
  1670.     break;
  1671.       block = BLOCK_SUPERBLOCK (block);
  1672.     }
  1673.  
  1674.   if (sal_chain)
  1675.     {
  1676.       struct sal_chain *tmp_chain;
  1677.  
  1678.       /* Count the number of entries.  */
  1679.       for (index = 0, tmp_chain = sal_chain; tmp_chain;
  1680.        tmp_chain = tmp_chain->next)
  1681.     index++;
  1682.  
  1683.       sals.nelts = index;
  1684.       sals.sals = (struct symtab_and_line *)
  1685.     xmalloc (index * sizeof (struct symtab_and_line));
  1686.       for (index = 0; sal_chain; sal_chain = sal_chain->next, index++)
  1687.     sals.sals[index] = sal_chain->sal;
  1688.     }
  1689.  
  1690.   return sals;
  1691. }
  1692.  
  1693. /* Commands to deal with catching exceptions.  */
  1694.  
  1695. void
  1696. catch_command_1 (arg, tempflag, from_tty)
  1697.      char *arg;
  1698.      int tempflag;
  1699.      int from_tty;
  1700. {
  1701.   /* First, translate ARG into something we can deal with in terms
  1702.      of breakpoints.  */
  1703.  
  1704.   struct symtabs_and_lines sals;
  1705.   struct symtab_and_line sal;
  1706.   register struct expression *cond = 0;
  1707.   register struct breakpoint *b;
  1708.   char *save_arg;
  1709.   int i;
  1710.   CORE_ADDR pc;
  1711.  
  1712.   sal.line = sal.pc = sal.end = 0;
  1713.   sal.symtab = 0;
  1714.  
  1715.   /* If no arg given, or if first arg is 'if ', all active catch clauses
  1716.      are breakpointed. */
  1717.  
  1718.   if (!arg || (arg[0] == 'i' && arg[1] == 'f' 
  1719.            && (arg[2] == ' ' || arg[2] == '\t')))
  1720.     {
  1721.       /* Grab all active catch clauses.  */
  1722.       sals = get_catch_sals (0);
  1723.     }
  1724.   else
  1725.     {
  1726.       /* Grab selected catch clauses.  */
  1727.       error ("catch NAME not implemeneted");
  1728. #if 0
  1729.       /* This isn't used; I don't know what it was for.  */
  1730.       sals = map_catch_names (arg, catch_breakpoint);
  1731. #endif
  1732.     }
  1733.  
  1734.   if (! sals.nelts) 
  1735.     return;
  1736.  
  1737.   save_arg = arg;
  1738.   for (i = 0; i < sals.nelts; i++)
  1739.     {
  1740.       sal = sals.sals[i];
  1741.       if (sal.pc == 0 && sal.symtab != 0)
  1742.     {
  1743.       pc = find_line_pc (sal.symtab, sal.line);
  1744.       if (pc == 0)
  1745.         error ("No line %d in file \"%s\".",
  1746.            sal.line, sal.symtab->filename);
  1747.     }
  1748.       else 
  1749.     pc = sal.pc;
  1750.       
  1751.       while (arg && *arg)
  1752.     {
  1753.       if (arg[0] == 'i' && arg[1] == 'f'
  1754.           && (arg[2] == ' ' || arg[2] == '\t'))
  1755.         cond = parse_exp_1 ((arg += 2, &arg), block_for_pc (pc), 0);
  1756.       else
  1757.         error ("Junk at end of arguments.");
  1758.     }
  1759.       arg = save_arg;
  1760.       sals.sals[i].pc = pc;
  1761.     }
  1762.  
  1763.   for (i = 0; i < sals.nelts; i++)
  1764.     {
  1765.       sal = sals.sals[i];
  1766.  
  1767.       if (from_tty)
  1768.     describe_other_breakpoints (sal.pc);
  1769.  
  1770.       b = set_raw_breakpoint (sal);
  1771.       b->number = ++breakpoint_count;
  1772.       b->cond = cond;
  1773.       if (tempflag)
  1774.     b->enable = temporary;
  1775.  
  1776.       printf ("Breakpoint %d at %s", b->number, local_hex_string(b->address));
  1777.       if (b->symtab)
  1778.     printf (": file %s, line %d.", b->symtab->filename, b->line_number);
  1779.       printf ("\n");
  1780.     }
  1781.  
  1782.   if (sals.nelts > 1)
  1783.     {
  1784.       printf ("Multiple breakpoints were set.\n");
  1785.       printf ("Use the \"delete\" command to delete unwanted breakpoints.\n");
  1786.     }
  1787.   free (sals.sals);
  1788. }
  1789.  
  1790. #if 0
  1791. /* These aren't used; I don't know what they were for.  */
  1792. /* Disable breakpoints on all catch clauses described in ARGS.  */
  1793. static void
  1794. disable_catch (args)
  1795.      char *args;
  1796. {
  1797.   /* Map the disable command to catch clauses described in ARGS.  */
  1798. }
  1799.  
  1800. /* Enable breakpoints on all catch clauses described in ARGS.  */
  1801. static void
  1802. enable_catch (args)
  1803.      char *args;
  1804. {
  1805.   /* Map the disable command to catch clauses described in ARGS.  */
  1806. }
  1807.  
  1808. /* Delete breakpoints on all catch clauses in the active scope.  */
  1809. static void
  1810. delete_catch (args)
  1811.      char *args;
  1812. {
  1813.   /* Map the delete command to catch clauses described in ARGS.  */
  1814. }
  1815. #endif /* 0 */
  1816.  
  1817. static void
  1818. catch_command (arg, from_tty)
  1819.      char *arg;
  1820.      int from_tty;
  1821. {
  1822.   catch_command_1 (arg, 0, from_tty);
  1823. }
  1824.  
  1825. static void
  1826. clear_command (arg, from_tty)
  1827.      char *arg;
  1828.      int from_tty;
  1829. {
  1830.   register struct breakpoint *b, *b1;
  1831.   struct symtabs_and_lines sals;
  1832.   struct symtab_and_line sal;
  1833.   register struct breakpoint *found;
  1834.   int i;
  1835.  
  1836.   if (arg)
  1837.     {
  1838.       sals = decode_line_spec (arg, 1);
  1839.     }
  1840.   else
  1841.     {
  1842.       sals.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line));
  1843.       sal.line = default_breakpoint_line;
  1844.       sal.symtab = default_breakpoint_symtab;
  1845.       sal.pc = 0;
  1846.       if (sal.symtab == 0)
  1847.     error ("No source file specified.");
  1848.  
  1849.       sals.sals[0] = sal;
  1850.       sals.nelts = 1;
  1851.     }
  1852.  
  1853.   for (i = 0; i < sals.nelts; i++)
  1854.     {
  1855.       /* If exact pc given, clear bpts at that pc.
  1856.      But if sal.pc is zero, clear all bpts on specified line.  */
  1857.       sal = sals.sals[i];
  1858.       found = (struct breakpoint *) 0;
  1859.       while (breakpoint_chain
  1860.          && (sal.pc ? breakpoint_chain->address == sal.pc
  1861.          : (breakpoint_chain->symtab == sal.symtab
  1862.             && breakpoint_chain->line_number == sal.line)))
  1863.     {
  1864.       b1 = breakpoint_chain;
  1865.       breakpoint_chain = b1->next;
  1866.       b1->next = found;
  1867.       found = b1;
  1868.     }
  1869.  
  1870.       ALL_BREAKPOINTS (b)
  1871.     while (b->next
  1872.            && b->next->address != NULL
  1873.            && (sal.pc ? b->next->address == sal.pc
  1874.            : (b->next->symtab == sal.symtab
  1875.               && b->next->line_number == sal.line)))
  1876.       {
  1877.         b1 = b->next;
  1878.         b->next = b1->next;
  1879.         b1->next = found;
  1880.         found = b1;
  1881.       }
  1882.  
  1883.       if (found == 0)
  1884.     {
  1885.       if (arg)
  1886.         error ("No breakpoint at %s.", arg);
  1887.       else
  1888.         error ("No breakpoint at this line.");
  1889.     }
  1890.  
  1891.       if (found->next) from_tty = 1; /* Always report if deleted more than one */
  1892.       if (from_tty) printf ("Deleted breakpoint%s ", found->next ? "s" : "");
  1893.       while (found)
  1894.     {
  1895.       if (from_tty) printf ("%d ", found->number);
  1896.       b1 = found->next;
  1897.       delete_breakpoint (found);
  1898.       found = b1;
  1899.     }
  1900.       if (from_tty) putchar ('\n');
  1901.     }
  1902.   free (sals.sals);
  1903. }
  1904.  
  1905. /* Delete breakpoint in BS if they are `delete' breakpoints.
  1906.    This is called after any breakpoint is hit, or after errors.  */
  1907.  
  1908. void
  1909. breakpoint_auto_delete (bs)
  1910.      bpstat bs;
  1911. {
  1912.   for (; bs; bs = bs->next)
  1913.     if (bs->breakpoint_at && bs->breakpoint_at->enable == delete)
  1914.       delete_breakpoint (bs->breakpoint_at);
  1915. }
  1916.  
  1917. /* Delete a breakpoint and clean up all traces of it in the data structures. */
  1918.  
  1919. static void
  1920. delete_breakpoint (bpt)
  1921.      struct breakpoint *bpt;
  1922. {
  1923.   register struct breakpoint *b;
  1924.   register bpstat bs;
  1925.  
  1926.   if (bpt->inserted)
  1927.       target_remove_breakpoint(bpt->address, bpt->shadow_contents);
  1928.  
  1929.   if (breakpoint_chain == bpt)
  1930.     breakpoint_chain = bpt->next;
  1931.  
  1932.   ALL_BREAKPOINTS (b)
  1933.     if (b->next == bpt)
  1934.       {
  1935.     b->next = bpt->next;
  1936.     break;
  1937.       }
  1938.  
  1939.   check_duplicates (bpt->address);
  1940.  
  1941.   free_command_lines (&bpt->commands);
  1942.   if (bpt->cond)
  1943.     free (bpt->cond);
  1944.   if (bpt->cond_string != NULL)
  1945.     free (bpt->cond_string);
  1946.   if (bpt->addr_string != NULL)
  1947.     free (bpt->addr_string);
  1948.  
  1949.   if (xgdb_verbose && bpt->number >=0)
  1950.     printf ("breakpoint #%d deleted\n", bpt->number);
  1951.  
  1952.   /* Be sure no bpstat's are pointing at it after it's been freed.  */
  1953.   /* FIXME, how can we find all bpstat's?  We just check stop_bpstat for now. */
  1954.   for (bs = stop_bpstat; bs; bs = bs->next)
  1955.     if (bs->breakpoint_at == bpt)
  1956.       bs->breakpoint_at = NULL;
  1957.   free (bpt);
  1958. }
  1959.  
  1960. static void map_breakpoint_numbers ();
  1961.  
  1962. static void
  1963. delete_command (arg, from_tty)
  1964.      char *arg;
  1965.      int from_tty;
  1966. {
  1967.  
  1968.   if (arg == 0)
  1969.     {
  1970.       /* Ask user only if there are some breakpoints to delete.  */
  1971.       if (!from_tty
  1972.       || (breakpoint_chain && query ("Delete all breakpoints? ", 0, 0)))
  1973.     {
  1974.       /* No arg; clear all breakpoints.  */
  1975.       while (breakpoint_chain)
  1976.         delete_breakpoint (breakpoint_chain);
  1977.     }
  1978.     }
  1979.   else
  1980.     map_breakpoint_numbers (arg, delete_breakpoint);
  1981. }
  1982.  
  1983. /* Reset a breakpoint given it's struct breakpoint * BINT.
  1984.    The value we return ends up being the return value from catch_errors.
  1985.    Unused in this case.  */
  1986.  
  1987. static int
  1988. breakpoint_re_set_one (bint)
  1989.      char *bint;
  1990. {
  1991.   struct breakpoint *b = (struct breakpoint *)bint;  /* get past catch_errs */
  1992.   int i;
  1993.   struct symtabs_and_lines sals;
  1994.   struct symtab_and_line sal;
  1995.   char *s;
  1996.  
  1997.   if (b->address != NULL && b->addr_string != NULL)
  1998.     {
  1999.       s = b->addr_string;
  2000.       sals = decode_line_1 (&s, 1, (struct symtab *)NULL, 0);
  2001.       for (i = 0; i < sals.nelts; i++)
  2002.     {
  2003.       sal = sals.sals[i];
  2004.       
  2005.       b->symtab = sal.symtab;
  2006.       b->line_number = sal.line;
  2007.       if (sal.pc == 0 && sal.symtab != 0)
  2008.         {
  2009.           sal.pc = find_line_pc (sal.symtab, sal.line);
  2010.           if (sal.pc == 0)
  2011.         error ("No line %d in file \"%s\".",
  2012.                sal.line, sal.symtab->filename);
  2013.         }
  2014.       b->address = sal.pc;
  2015.  
  2016.       if (b->cond_string != NULL)
  2017.         {
  2018.           s = b->cond_string;
  2019.           b->cond = parse_exp_1 (&s, block_for_pc (sal.pc), 0);
  2020.         }
  2021.       
  2022.       check_duplicates (b->address);
  2023.  
  2024.       mention (b);
  2025.     }
  2026.       free (sals.sals);
  2027.     }
  2028.   else
  2029.     {
  2030.       /* Anything without a string can't be re-set. */
  2031.       delete_breakpoint (b);
  2032.     }
  2033.   return 0;
  2034. }
  2035.  
  2036. /* Re-set all breakpoints after symbols have been re-loaded.  */
  2037. void
  2038. breakpoint_re_set ()
  2039. {
  2040.   struct breakpoint *b;
  2041.   
  2042.   ALL_BREAKPOINTS (b)
  2043.     {
  2044.       b->symtab = 0;        /* Be sure we don't point to old dead symtab */
  2045.       (void) catch_errors (breakpoint_re_set_one, (char *) b, 
  2046.                "Error in re-setting breakpoint:\n");
  2047.     }
  2048.  
  2049.   /* Blank line to finish off all those mention() messages we just printed.  */
  2050.   printf_filtered ("\n");
  2051. }
  2052.  
  2053. /* Set ignore-count of breakpoint number BPTNUM to COUNT.
  2054.    If from_tty is nonzero, it prints a message to that effect,
  2055.    which ends with a period (no newline).  */
  2056.  
  2057. void
  2058. set_ignore_count (bptnum, count, from_tty)
  2059.      int bptnum, count, from_tty;
  2060. {
  2061.   register struct breakpoint *b;
  2062.  
  2063.   if (count < 0)
  2064.     count = 0;
  2065.  
  2066.   ALL_BREAKPOINTS (b)
  2067.     if (b->number == bptnum)
  2068.       {
  2069.     b->ignore_count = count;
  2070.     if (!from_tty)
  2071.       return;
  2072.     else if (count == 0)
  2073.       printf ("Will stop next time breakpoint %d is reached.", bptnum);
  2074.     else if (count == 1)
  2075.       printf ("Will ignore next crossing of breakpoint %d.", bptnum);
  2076.     else
  2077.       printf ("Will ignore next %d crossings of breakpoint %d.",
  2078.           count, bptnum);
  2079.     return;
  2080.       }
  2081.  
  2082.   error ("No breakpoint number %d.", bptnum);
  2083. }
  2084.  
  2085. /* Clear the ignore counts of all breakpoints.  */
  2086. void
  2087. breakpoint_clear_ignore_counts ()
  2088. {
  2089.   struct breakpoint *b;
  2090.  
  2091.   ALL_BREAKPOINTS (b)
  2092.     b->ignore_count = 0;
  2093. }
  2094.  
  2095. /* Command to set ignore-count of breakpoint N to COUNT.  */
  2096.  
  2097. static void
  2098. ignore_command (args, from_tty)
  2099.      char *args;
  2100.      int from_tty;
  2101. {
  2102.   char *p = args;
  2103.   register int num;
  2104.  
  2105.   if (p == 0)
  2106.     error_no_arg ("a breakpoint number");
  2107.   
  2108.   num = get_number (&p);
  2109.  
  2110.   if (*p == 0)
  2111.     error ("Second argument (specified ignore-count) is missing.");
  2112.  
  2113.   set_ignore_count (num,
  2114.             longest_to_int (value_as_long (parse_and_eval (p))),
  2115.             from_tty);
  2116.   printf ("\n");
  2117. }
  2118.  
  2119. /* Call FUNCTION on each of the breakpoints
  2120.    whose numbers are given in ARGS.  */
  2121.  
  2122. static void
  2123. map_breakpoint_numbers (args, function)
  2124.      char *args;
  2125.      void (*function) ();
  2126. {
  2127.   register char *p = args;
  2128.   char *p1;
  2129.   register int num;
  2130.   register struct breakpoint *b;
  2131.  
  2132.   if (p == 0)
  2133.     error_no_arg ("one or more breakpoint numbers");
  2134.  
  2135.   while (*p)
  2136.     {
  2137.       p1 = p;
  2138.       
  2139.       num = get_number (&p1);
  2140.  
  2141.       ALL_BREAKPOINTS (b)
  2142.     if (b->number == num)
  2143.       {
  2144.         function (b);
  2145.         goto win;
  2146.       }
  2147.       printf ("No breakpoint number %d.\n", num);
  2148.     win:
  2149.       p = p1;
  2150.     }
  2151. }
  2152.  
  2153. static void
  2154. enable_breakpoint (bpt)
  2155.      struct breakpoint *bpt;
  2156. {
  2157.   bpt->enable = enabled;
  2158.  
  2159.   if (xgdb_verbose && bpt->number >= 0)
  2160.     printf ("breakpoint #%d enabled\n", bpt->number);
  2161.  
  2162.   check_duplicates (bpt->address);
  2163.   if (bpt->val != NULL)
  2164.     {
  2165.       if (bpt->exp_valid_block != NULL
  2166.        && !contained_in (get_selected_block (), bpt->exp_valid_block))
  2167.     {
  2168.       printf_filtered ("\
  2169. Cannot enable watchpoint %d because the block in which its expression\n\
  2170. is valid is not currently in scope.\n", bpt->number);
  2171.       return;
  2172.     }
  2173.  
  2174.       value_free (bpt->val);
  2175.  
  2176.       bpt->val = evaluate_expression (bpt->exp);
  2177.       release_value (bpt->val);
  2178.     }
  2179. }
  2180.  
  2181. /* ARGSUSED */
  2182. static void
  2183. enable_command (args, from_tty)
  2184.      char *args;
  2185.      int from_tty;
  2186. {
  2187.   struct breakpoint *bpt;
  2188.   if (args == 0)
  2189.     ALL_BREAKPOINTS (bpt)
  2190.       enable_breakpoint (bpt);
  2191.   else
  2192.     map_breakpoint_numbers (args, enable_breakpoint);
  2193. }
  2194.  
  2195. static void
  2196. disable_breakpoint (bpt)
  2197.      struct breakpoint *bpt;
  2198. {
  2199.   bpt->enable = disabled;
  2200.  
  2201.   if (xgdb_verbose && bpt->number >= 0)
  2202.     printf ("breakpoint #%d disabled\n", bpt->number);
  2203.  
  2204.   check_duplicates (bpt->address);
  2205. }
  2206.  
  2207. /* ARGSUSED */
  2208. static void
  2209. disable_command (args, from_tty)
  2210.      char *args;
  2211.      int from_tty;
  2212. {
  2213.   register struct breakpoint *bpt;
  2214.   if (args == 0)
  2215.     ALL_BREAKPOINTS (bpt)
  2216.       disable_breakpoint (bpt);
  2217.   else
  2218.     map_breakpoint_numbers (args, disable_breakpoint);
  2219. }
  2220.  
  2221. static void
  2222. enable_once_breakpoint (bpt)
  2223.      struct breakpoint *bpt;
  2224. {
  2225.   bpt->enable = temporary;
  2226.  
  2227.   check_duplicates (bpt->address);
  2228. }
  2229.  
  2230. /* ARGSUSED */
  2231. static void
  2232. enable_once_command (args, from_tty)
  2233.      char *args;
  2234.      int from_tty;
  2235. {
  2236.   map_breakpoint_numbers (args, enable_once_breakpoint);
  2237. }
  2238.  
  2239. static void
  2240. enable_delete_breakpoint (bpt)
  2241.      struct breakpoint *bpt;
  2242. {
  2243.   bpt->enable = delete;
  2244.  
  2245.   check_duplicates (bpt->address);
  2246. }
  2247.  
  2248. /* ARGSUSED */
  2249. static void
  2250. enable_delete_command (args, from_tty)
  2251.      char *args;
  2252.      int from_tty;
  2253. {
  2254.   map_breakpoint_numbers (args, enable_delete_breakpoint);
  2255. }
  2256.  
  2257. /*
  2258.  * Use default_breakpoint_'s, or nothing if they aren't valid.
  2259.  */
  2260. struct symtabs_and_lines
  2261. decode_line_spec_1 (string, funfirstline)
  2262.      char *string;
  2263.      int funfirstline;
  2264. {
  2265.   struct symtabs_and_lines sals;
  2266.   if (string == 0)
  2267.     error ("Empty line specification.");
  2268.   if (default_breakpoint_valid)
  2269.     sals = decode_line_1 (&string, funfirstline,
  2270.               default_breakpoint_symtab, default_breakpoint_line);
  2271.   else
  2272.     sals = decode_line_1 (&string, funfirstline, (struct symtab *)NULL, 0);
  2273.   if (*string)
  2274.     error ("Junk at end of line specification: %s", string);
  2275.   return sals;
  2276. }
  2277.  
  2278.  
  2279. /* Chain containing all defined enable commands.  */
  2280.  
  2281. extern struct cmd_list_element 
  2282.   *enablelist, *disablelist,
  2283.   *deletelist, *enablebreaklist;
  2284.  
  2285. extern struct cmd_list_element *cmdlist;
  2286.  
  2287. void
  2288. _initialize_breakpoint ()
  2289. {
  2290.   breakpoint_chain = 0;
  2291.   /* Don't bother to call set_breakpoint_count.  $bpnum isn't useful
  2292.      before a breakpoint is set.  */
  2293.   breakpoint_count = 0;
  2294.  
  2295.   add_com ("ignore", class_breakpoint, ignore_command,
  2296.        "Set ignore-count of breakpoint number N to COUNT.");
  2297.  
  2298.   add_com ("commands", class_breakpoint, commands_command,
  2299.        "Set commands to be executed when a breakpoint is hit.\n\
  2300. Give breakpoint number as argument after \"commands\".\n\
  2301. With no argument, the targeted breakpoint is the last one set.\n\
  2302. The commands themselves follow starting on the next line.\n\
  2303. Type a line containing \"end\" to indicate the end of them.\n\
  2304. Give \"silent\" as the first line to make the breakpoint silent;\n\
  2305. then no output is printed when it is hit, except what the commands print.");
  2306.  
  2307.   add_com ("condition", class_breakpoint, condition_command,
  2308.        "Specify breakpoint number N to break only if COND is true.\n\
  2309. N is an integer; COND is an expression to be evaluated whenever\n\
  2310. breakpoint N is reached.  ");
  2311.  
  2312.   add_com ("tbreak", class_breakpoint, tbreak_command,
  2313.        "Set a temporary breakpoint.  Args like \"break\" command.\n\
  2314. Like \"break\" except the breakpoint is only enabled temporarily,\n\
  2315. so it will be disabled when hit.  Equivalent to \"break\" followed\n\
  2316. by using \"enable once\" on the breakpoint number.");
  2317.  
  2318.   add_prefix_cmd ("enable", class_breakpoint, enable_command,
  2319.           "Enable some breakpoints.\n\
  2320. Give breakpoint numbers (separated by spaces) as arguments.\n\
  2321. With no subcommand, breakpoints are enabled until you command otherwise.\n\
  2322. This is used to cancel the effect of the \"disable\" command.\n\
  2323. With a subcommand you can enable temporarily.",
  2324.           &enablelist, "enable ", 1, &cmdlist);
  2325.  
  2326.   add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command,
  2327.           "Enable some breakpoints.\n\
  2328. Give breakpoint numbers (separated by spaces) as arguments.\n\
  2329. This is used to cancel the effect of the \"disable\" command.\n\
  2330. May be abbreviated to simply \"enable\".\n",
  2331.           &enablebreaklist, "enable breakpoints ", 1, &enablelist);
  2332.  
  2333.   add_cmd ("once", no_class, enable_once_command,
  2334.        "Enable breakpoints for one hit.  Give breakpoint numbers.\n\
  2335. If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
  2336. See the \"tbreak\" command which sets a breakpoint and enables it once.",
  2337.        &enablebreaklist);
  2338.  
  2339.   add_cmd ("delete", no_class, enable_delete_command,
  2340.        "Enable breakpoints and delete when hit.  Give breakpoint numbers.\n\
  2341. If a breakpoint is hit while enabled in this fashion, it is deleted.",
  2342.        &enablebreaklist);
  2343.  
  2344.   add_cmd ("delete", no_class, enable_delete_command,
  2345.        "Enable breakpoints and delete when hit.  Give breakpoint numbers.\n\
  2346. If a breakpoint is hit while enabled in this fashion, it is deleted.",
  2347.        &enablelist);
  2348.  
  2349.   add_cmd ("once", no_class, enable_once_command,
  2350.        "Enable breakpoints for one hit.  Give breakpoint numbers.\n\
  2351. If a breakpoint is hit while enabled in this fashion, it becomes disabled.\n\
  2352. See the \"tbreak\" command which sets a breakpoint and enables it once.",
  2353.        &enablelist);
  2354.  
  2355.   add_prefix_cmd ("disable", class_breakpoint, disable_command,
  2356.        "Disable some breakpoints.\n\
  2357. Arguments are breakpoint numbers with spaces in between.\n\
  2358. To disable all breakpoints, give no argument.\n\
  2359. A disabled breakpoint is not forgotten, but has no effect until reenabled.",
  2360.           &disablelist, "disable ", 1, &cmdlist);
  2361.   add_com_alias ("dis", "disable", class_breakpoint, 1);
  2362.   add_com_alias ("disa", "disable", class_breakpoint, 1);
  2363.  
  2364.   add_cmd ("breakpoints", class_alias, disable_command,
  2365.        "Disable some breakpoints.\n\
  2366. Arguments are breakpoint numbers with spaces in between.\n\
  2367. To disable all breakpoints, give no argument.\n\
  2368. A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\
  2369. This command may be abbreviated \"disable\".",
  2370.        &disablelist);
  2371.  
  2372.   add_prefix_cmd ("delete", class_breakpoint, delete_command,
  2373.        "Delete some breakpoints or auto-display expressions.\n\
  2374. Arguments are breakpoint numbers with spaces in between.\n\
  2375. To delete all breakpoints, give no argument.\n\
  2376. \n\
  2377. Also a prefix command for deletion of other GDB objects.\n\
  2378. The \"unset\" command is also an alias for \"delete\".",
  2379.           &deletelist, "delete ", 1, &cmdlist);
  2380.   add_com_alias ("d", "delete", class_breakpoint, 1);
  2381.  
  2382.   add_cmd ("breakpoints", class_alias, delete_command,
  2383.        "Delete some breakpoints or auto-display expressions.\n\
  2384. Arguments are breakpoint numbers with spaces in between.\n\
  2385. To delete all breakpoints, give no argument.\n\
  2386. This command may be abbreviated \"delete\".",
  2387.        &deletelist);
  2388.  
  2389.   add_com ("clear", class_breakpoint, clear_command,
  2390.        "Clear breakpoint at specified line or function.\n\
  2391. Argument may be line number, function name, or \"*\" and an address.\n\
  2392. If line number is specified, all breakpoints in that line are cleared.\n\
  2393. If function is specified, breakpoints at beginning of function are cleared.\n\
  2394. If an address is specified, breakpoints at that address are cleared.\n\n\
  2395. With no argument, clears all breakpoints in the line that the selected frame\n\
  2396. is executing in.\n\
  2397. \n\
  2398. See also the \"delete\" command which clears breakpoints by number.");
  2399.  
  2400.   add_com ("break", class_breakpoint, break_command,
  2401.        "Set breakpoint at specified line or function.\n\
  2402. Argument may be line number, function name, or \"*\" and an address.\n\
  2403. If line number is specified, break at start of code for that line.\n\
  2404. If function is specified, break at start of code for that function.\n\
  2405. If an address is specified, break at that exact address.\n\
  2406. With no arg, uses current execution address of selected stack frame.\n\
  2407. This is useful for breaking on return to a stack frame.\n\
  2408. \n\
  2409. Multiple breakpoints at one place are permitted, and useful if conditional.\n\
  2410. \n\
  2411. Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
  2412.   add_com_alias ("b", "break", class_run, 1);
  2413.   add_com_alias ("br", "break", class_run, 1);
  2414.   add_com_alias ("bre", "break", class_run, 1);
  2415.   add_com_alias ("brea", "break", class_run, 1);
  2416.  
  2417.   add_info ("breakpoints", breakpoints_info,
  2418.         "Status of all breakpoints, or breakpoint number NUMBER.\n\
  2419. Second column is \"y\" for enabled breakpoint, \"n\" for disabled,\n\
  2420. \"o\" for enabled once (disable when hit), \"d\" for enable but delete when hit.\n\
  2421. Then come the address and the file/line number.\n\n\
  2422. Convenience variable \"$_\" and default examine address for \"x\"\n\
  2423. are set to the address of the last breakpoint listed.\n\n\
  2424. Convenience variable \"$bpnum\" contains the number of the last\n\
  2425. breakpoint set.");
  2426.  
  2427.   add_com ("catch", class_breakpoint, catch_command,
  2428.          "Set breakpoints to catch exceptions that are raised.\n\
  2429. Argument may be a single exception to catch, multiple exceptions\n\
  2430. to catch, or the default exception \"default\".  If no arguments\n\
  2431. are given, breakpoints are set at all exception handlers catch clauses\n\
  2432. within the current scope.\n\
  2433. \n\
  2434. A condition specified for the catch applies to all breakpoints set\n\
  2435. with this command\n\
  2436. \n\
  2437. Do \"help breakpoints\" for info on other commands dealing with breakpoints.");
  2438.  
  2439.   add_com ("watch", class_breakpoint, watch_command,
  2440.        "Set a watchpoint for an expression.\n\
  2441. A watchpoint stops execution of your program whenever the value of\n\
  2442. an expression changes.");
  2443.  
  2444.   add_info ("watchpoints", watchpoints_info,
  2445.         "Status of all watchpoints, or watchpoint number NUMBER.\n\
  2446. Second column is \"y\" for enabled watchpoints, \"n\" for disabled.");
  2447. }
  2448.